package com.car.util;

import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class Test2 {
 //输入一个月份，判断周数
 public static void main(String args[]) throws Exception{
	 Calendar c_now = new GregorianCalendar();
	 Calendar c_begin = new GregorianCalendar();
     Calendar c_end = new GregorianCalendar();
     DateFormatSymbols dfs = new DateFormatSymbols(); 
     String[] weeks = dfs.getWeekdays();
      
     //设置参数，年，月
     String date = "2016-5-5";
     SimpleDateFormat df =new SimpleDateFormat("yyyy-M-d");  
     java.util.Date  cDate  =  df.parse(date);  
     c_now.setTime(cDate);
     int year=c_now.get(Calendar.YEAR);
     int month = c_now.get(Calendar.MONTH)+1;
     int[] days = {0,31,28,31,30,31,30,31,31,30,31,30,31};
     if (year % 4==0) days[2]=29;//大年
     	c_begin.set(year, month-1, 1); //月 0-11  天 0-
     	c_end.set(year, month-1, days[month]);

     	int count = 1;
     	c_end.add(Calendar.DAY_OF_YEAR, 1);  //结束日期下滚一天是为了包含最后一天      
     	while(c_begin.before(c_end)){
     		System.out.println("第"+count+"周  日期："+new java.sql.Date(c_begin.getTime().getTime())+", "+weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
     		if(c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
     			count++;
     		}
     		c_begin.add(Calendar.DAY_OF_YEAR, 1);
     	}
     	System.out.println("共计（跨越）："+(count-1) +"周");
  	} 
 	
  }
